package com.fuint.module.clientApi.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.fuint.common.enums.SettingTypeEnum;
import com.fuint.common.service.MerchantService;
import com.fuint.common.service.SettingService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtMerchant;
import com.fuint.repository.model.MtSetting;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Api(tags = "会员端-全局配置")
@RestController
@RequestMapping(value = "/clientApi/setting")
public class ClientSettingController extends BaseController {

    private final SettingService settingService;

    @Autowired
    ClientSettingController(SettingService settingService) {
        this.settingService = settingService;
    }

    @ApiOperation(value = "获取全局配置")
    @GetMapping()
    public ResponseObject getShopSwitchSetting() throws BusinessCheckException {
        List<MtSetting> settingList = settingService.getSettingList(0, SettingTypeEnum.FRONT_GLOBAL.getKey());
        if (CollUtil.isEmpty(settingList)) {
            return getSuccessResult(new HashMap<>());
        }

        Map<String, String> data = new HashMap<>(settingList.size());
        for (MtSetting setting : settingList) {
            if (Objects.isNull(setting)) {
                continue;
            }
            data.put(setting.getName(), setting.getValue());
        }
        return getSuccessResult(data);
    }
}
